package com.github.leecho.spring.cloud.gateway.dubbo.client;

import com.github.leecho.spring.cloud.gateway.dubbo.route.DubboRoute;
import com.github.leecho.spring.cloud.gateway.dubbo.route.DubboRoute.DubboProvider;
import lombok.Setter;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.rpc.service.GenericService;

/**
 * @author LIQIU
 * @date 2021/7/28 8:46
 */
public class DefaultDubboGenericServiceFactory implements DubboGenericServiceFactory {

	/**
	 * 异步执行配置
	 */
	@Setter
	private boolean invokeAsync;

	/**
	 * 重试次数
	 */
	@Setter
	private int retries;

	@Setter
	private boolean check;


	public DefaultDubboGenericServiceFactory() {
		this.invokeAsync = false;
		this.retries = 0;
		this.check = false;
	}

	@Override
	public ReferenceBean<GenericService> build(DubboProvider dubboProvider) {
		ReferenceBean<GenericService> referenceBean = new ReferenceBean<>();
		referenceBean.setGeneric(true);
		referenceBean.setInterface(dubboProvider.getInterfaceClass());
		referenceBean.setVersion(dubboProvider.getVersion());
		referenceBean.setGroup(dubboProvider.getGroup());
		referenceBean.setCheck(check);
		referenceBean.setRetries(retries);
		referenceBean.setAsync(invokeAsync);
		return referenceBean;

	}
}
